﻿<?php 

error_reporting(E_ALL ^ E_NOTICE); 
$_GET['word'] = urlencode($_GET['word']);
if(isset($_GET['jkm']) && $_GET['jkm'] != '0')
{
    require ('quanju.php');
    if(isset($_GET['jzdj']) && $_GET['jzdj'] == '1' && isset($_GET['sjh']) && $_GET['sjh']){
        $_GET['word'] = trim($_GET['word']);
        $result = $conn->query("SELECT * FROM hg002 WHERE sjh = {$_GET['sjh']}");
        if($result){
            if($row = mysqli_fetch_array($result)){
                $sj = intval($row['jkmsj']);
                if (time() - $sj <= 60 * 5){
                    $jkm = $row['jkm'];    
                    $_SESSION['df_sjh'] = $row['sjh'];
                    $_SESSION['df_jkm'] = $jkm;
                    header( "Location:s?bjs=1&word={$_GET['word']}&jkm={$jkm}&sjh={$row['sjh']}&ie=utf-8"); 
                    exit;
                    
                }
            }
        }
    }
    $jkm = $_GET['jkm'];    
    if(isset($_GET['word']))$_GET['word'] = trim($_GET['word']);
    else $_GET['word'] = '';
    
    $yaodizeng = 0;
    if(isset($_GET['dizeng']) && substr($_GET['dizeng'],0,1) == 'd'){
        $dizeng = $_GET['dizeng'];
        $result = $conn->query("SELECT * FROM hg002 WHERE jkm REGEXP '^{$dizeng}'");
        
    }
    if(!$result || $result->num_rows < 1){
        if($jkm > 0){
            $result = $conn->query("SELECT * FROM hg002 WHERE jkm like '{$jkm}!%'");
        }else{
            $jkm = -$jkm;
            $result = $conn->query("SELECT * FROM hg002 WHERE jkm like '%!{$jkm}'");        
        }
    }else{
        $_GET['jkm'] = $dizeng;
        $yaodizeng = 1;
    }
    $wgjc = 0;
    if(!$_GET['word']){
        $_GET['word'] = '百度今日数据';
        $wgjc = 1;
    }
    if($result)
    {
        while ($row = mysqli_fetch_array($result)) {
            $sj = intval($row['jkmsj']);
            if (time() - $sj <= 60 * 5){
                session_start();
                $_SESSION['df_sjh'] = $row['sjh'];
                $_SESSION['df_jkm'] = $_GET['jkm'];
                $_SESSION['df_Xdjjr'] = $row['Xdjjr'];
                if($_SESSION['df_Xdjjr'] == 1 && $_GET['r'] > 0){
                    echo '<script>window.parent.sftz(2);</script>';
                    exit;
                }
                if($row['Xdjgjc'] && $wgjc == 1){
                    $_GET['word'] = $row['Xdjgjc'];
                }
                if($_GET['r'] > 0){
                    header( "Location:s?bjs=1&word={$_GET['word']}&jkm={$_GET['jkm']}&sjh={$row['sjh']}&ie=utf-8"); 
                }else {
                    if($yaodizeng == 1)
                        header( "Location:s?word={$_GET['word']}&jkm={$_GET['jkm']}&sjh={$row['sjh']}&hgyzl=3.14159&ie=utf-8"); 
                    else
                        header( "Location:s?word={$_GET['word']}&bjs=1&jkm={$_GET['jkm']}&sjh={$row['sjh']}&ie=utf-8"); 
                }
                exit;
            }
            
        }
    }
    if($jkm > 0){
        $result = $conn->query("SELECT * FROM hg002 WHERE jkm='{$_GET['jkm']}'");
        if($result){
            while ($row = mysqli_fetch_array($result)) {
                $sj = intval($row['jkmsj']);
                if (time() - $sj <= 60 * 5){
                    session_start();
                    $_SESSION['df_sjh'] = $row['sjh'];
                    $_SESSION['df_jkm'] = $_GET['jkm'];
                    header( "Location:s?bjs=1&word={$_GET['word']}&jkm={$_GET['jkm']}&sjh={$row['sjh']}&ie=utf-8"); 
                    exit;
                }
            }       
        }
    }
    $conn->close();
}
if(isset($_GET['r']) && $_GET['r'] > 0){
    echo '<script>window.parent.sftz(1);</script>';
}else header( "Location:http://m.baidu.com/s?word=".$_GET['word']); 
exit;
?>